package com.example.springbootexam.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springbootexam.bean.Exam;
import com.example.springbootexam.bean.ExamDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zz
 * @since 2024-08-14
 */
public interface ExamMapper extends BaseMapper<Exam> {

    @Select("select * from exam where pid=#{pid} and uid=#{uid}")
    @Results(id="rm1",
            value={
                    @Result(column = "id",property = "id", id = true),
                    @Result(column = "id",property = "details", many = @Many(
                            select = "selectDetailByPid"
                    ))
            })
    Exam findById(@Param("pid") int pid, @Param("uid") int uid);

    @Select("select * from exam_detail where eid=#{eid}")
    @Results(id="rm2",
            value={
                    @Result(column = "id",property = "id", id = true),
                    @Result(column = "qid",property = "qid"),
                    @Result(column = "qid",property = "question", one = @One(
                            select = "com.example.springbootexam.mapper.QuestionMapper.selectById"
                    ))
            })
    List<ExamDetail> selectDetailByPid(int eid);

}
